// 住院管理
<template>
  <el-row>
      <TopManu

      ></TopManu>
    <el-col :span="24">

      <el-col :span="24" class="hospitalNurse-right">
         <el-form :inline="true" class="demo-form-inline" v-model="formInline">
          <el-form-item label="搜索">
            <el-input
              placeholder="请输入姓名/门诊号/身份证号"
              v-model="formInline.rightKeyValue"
              clearable
              @change="radiochang"
            >
              <el-button slot="append" icon="el-icon-search" @click="radiochang">
                查询
              </el-button>
            </el-input>
          </el-form-item>
          <el-form-item label='类型'>
              <el-select v-model="formInline.rightRadio"  @change="radiochang" multiple placeholder="类型">
    <el-option
      v-for="item in Radiooptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
          </el-form-item>
              <el-form-item label='范围'>
              <el-select v-model="formInline.range"  @change="radiochang"  placeholder="范围">
    <el-option
      v-for="item in Radiooptions2"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
          </el-form-item>
              <el-form-item label='病区'>
              <el-select v-model="formInline.room"  @change="radiochang"  placeholder="范围">
    <el-option

      label="全部"
      value="">
    </el-option>
    <el-option
      v-for="item in getBuildlist"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
          </el-form-item>
                <!-- <el-form-item label='时间'>
          <el-date-picker
      v-model="formInline.times"
      type="date"
      placeholder="选择日期"
      format="yyyy 年 MM 月 dd 日"
      value-format="yyyy-MM-dd"
      @change="radiochang">
    </el-date-picker>
          </el-form-item> -->

        </el-form>

        <el-table :data="patientlist"
        :row-click="rowclick"
        border style="width: 100%">
          <el-table-column prop="room_name" label="病区">
               <template slot-scope="scope">
                 {{scope.row.room_info[1]}}
                  </template>
          </el-table-column>
          <el-table-column prop="room_name" label="房间">
             <template slot-scope="scope">
                 {{scope.row.room_info[2]}}
                  </template>  </el-table-column>
          <el-table-column prop="room_name" label="床位">
             <template slot-scope="scope">
                 {{scope.row.room_info[3]}}
                  </template>  </el-table-column>
          <el-table-column prop="member.name" label="姓名"> </el-table-column>
          <el-table-column prop="member.gender" label="性别"> </el-table-column>
          <el-table-column prop="member.age" label="年龄"> </el-table-column>
          <el-table-column prop="wallet.wallet_income" label="总押金">
          </el-table-column>

          <el-table-column prop="wallet.balance" label="总费用">
          </el-table-column>
           <el-table-column prop="wallet.wallet_money" label="可用押金">
          </el-table-column>
           <el-table-column prop="get_node.deposit_warn" label="押金警示">
          </el-table-column>
           <el-table-column prop="wallet.wallet_outcome" label="已结金额">
          </el-table-column>
             <!-- <el-table-column prop="wallet.wallet_income" label="上次催缴时间">
          </el-table-column> -->
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-dropdown @command="handleCommand" trigger="click">
                <span class="el-dropdown-link">
                  更多<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="[scope.row.id,scope.$index,'y']"
                    >押金</el-dropdown-item
                  >
                   <!-- <el-dropdown-item :command="[scope.row.id,scope.$index,'c']">撤销住院</el-dropdown-item>
                  <el-dropdown-item :command="[scope.row.id,scope.$index,'x']">修改信息</el-dropdown-item> -->
                  <el-dropdown-item  :command="[scope.row.id,scope.$index,'tk']">退款</el-dropdown-item>
                  <el-dropdown-item  :command="[scope.row.id,scope.$index,'dy']">押金打印</el-dropdown-item>
                   <!-- <el-dropdown-item disabled>催收打印</el-dropdown-item> -->
                  <el-dropdown-item  :command="[scope.row.id,scope.$index,'mx']">明细</el-dropdown-item>

                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
   <el-pagination
            background
            style="float:right"
            @size-change="handleSizeChange"
            :current-page="formInline.page"
            :page-sizes="[10, 20, 30, 100]"
            :page-size="formInline.limit"
            layout="sizes , total , prev, pager, next , jumper"
            @current-change="handlePagination"
            :total="total">
            </el-pagination>
      </el-col>
    </el-col>

    <!-- 押金弹框 -->
       <el-dialog :close-on-click-modal='false' title="押金" @close='qingchu' :visible.sync="dialogdeposit" width='70%'>
           <infocrad :id='patientinfo.id' ref='userinfn'></infocrad>
            <viewTitle text="押金信息" style="font-size:20px;margin-bottom:20px" />

      <el-col :span="24">

        <el-col :span="10">
          <el-form
            label-position="right"
            label-width="100px"
            :model="orderinfo"
          >
            <el-form-item label="微信">
              <el-input
                v-model="orderinfo.payment[0].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="支付宝">
              <el-input
                v-model="orderinfo.payment[1].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="现金">
              <el-input
                v-model="orderinfo.payment[2].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联">
              <el-input
                v-model="orderinfo.payment[3].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="预存">
              <el-input
                v-model="orderinfo.payment[4].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="医保">
              <el-input
                v-model="orderinfo.payment[5].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="总计">
              <el-input v-model="moneysum" disabled></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="2">
          <div style="width:20px">-</div>
        </el-col>
        <el-col :span="10">
          <el-form
            label-position="right"
            label-width="100px"
            :model="orderinfo"
          >
            <el-form-item label="小写">
              <el-input v-model="moneysum" disabled></el-input>
            </el-form-item>
            <el-form-item label="大写">
              <el-input v-model="damoneysum" disabled></el-input>
            </el-form-item>

            <el-form-item label="说明">
              <el-input type="textarea" v-model="orderinfo.des"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogdeposit = false">取 消</el-button>
        <el-button type="success" @click="handedeposit">保 存</el-button>
      </div>
    </el-dialog>

    <!-- 退款 -->
       <el-dialog :close-on-click-modal='false' title="退款" @close='qingchu' :visible.sync="dialogdeposit2" width='70%'>
           <infocrad :id='patientinfo.id' ref='userinfn'></infocrad>
            <viewTitle text="退款信息" style="font-size:20px;margin-bottom:20px" />

      <el-col :span="24">

        <el-col :span="10">
          <el-form
            label-position="right"
            label-width="100px"
            :model="orderinfo"
          >
            <el-form-item label="微信">
              <el-input
                v-model="orderinfo.payment[0].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="支付宝">
              <el-input
                v-model="orderinfo.payment[1].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="现金">
              <el-input
                v-model="orderinfo.payment[2].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联">
              <el-input
                v-model="orderinfo.payment[3].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="预存">
              <el-input
                v-model="orderinfo.payment[4].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="医保">
              <el-input
                v-model="orderinfo.payment[5].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
            <el-form-item label="总计">
              <el-input v-model="moneysum" disabled></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="2">
          <div style="width:20px"> &nbsp;</div>
        </el-col>
        <el-col :span="10">
          <el-form
            label-position="right"
            label-width="100px"
            :model="orderinfo"
          >
            <el-form-item label="小写">
              <el-input v-model="moneysum" disabled></el-input>
            </el-form-item>
            <el-form-item label="大写">
              <el-input v-model="damoneysum" disabled></el-input>
            </el-form-item>

            <el-form-item label="说明">
              <el-input type="textarea" v-model="orderinfo.des"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogdeposit2 = false">取 消</el-button>
        <el-button type="success" @click="refundDeposit">保 存</el-button>
      </div>
    </el-dialog>

    <!-- 退款 -->
       <el-dialog :close-on-click-modal='false' title="押金明细" @close='qingchu' :visible.sync="dialogdeposit3" width='70%'>
           <infocrad :id='patientinfo.id' ref='userinfn'></infocrad>
            <viewTitle text="押金明细" style="font-size:20px;margin-bottom:20px" />

      <el-col :span="24">

          <FromList  :tableData="posiDetaillist" :tableTitle="wardTitle"></FromList>
      </el-col>
      <div slot="footer" class="dialog-footer">

        <el-button type="success" @click="dialogdeposit3 = false">确定</el-button>
      </div>
    </el-dialog>
       <el-dialog :fullscreen='true' :close-on-click-modal='false' title="打印收据" center :visible.sync="shoujulogdeposit">
        <costR :id="patientinfo.id"></costR>
      <div slot="footer" class="dialog-footer" style='padding:0px;margin:5px'>
<!--      <el-button type="success" @click="shoujulogdeposit = false">取 消</el-button>-->
        <!-- <el-button type="success" type="success" @click="tijiaochuyuan">确定</el-button> -->
      </div>
    </el-dialog>

  </el-row>
</template>

<script>
import FromList from "@/forComponents/fromList/fromList";
import TopManu from "@/components/TopMenu";
import ViewTitle from "@/forComponents/viewTitle";
import infocrad from "../components/infocrad.vue";
import costR from "./comp/costRecord.vue";
import { getdictIndex } from "@/api/register";
import { getMemberDepositList } from "@/api/DepositList";
import { createDepositOrder,getNurseLevel,getAllIcu,refundDeposit,
getDeposiDetail } from "@/api/zhuyanre"
let that;
export default {
  data() {
    return {
      wardData: [
        {
          wardName: "病区一",
          hold: 100,
          null: 0
        }
      ],
      dialogdeposit3:false,
      shoujulogdeposit:false,
      wardTitle: [
        {
          prop: "order_num",
          name: "订单号",
          type: 1,
          width: "300"
        },
         {
          prop: "des",
          name: "缴纳类型",
          type: 1
        },
        {
          prop: "money",
          name: "金额",
          type: 1
        },
         {
          prop: "get_user_real_name",
          name: "操作员",
          type: 1
        },
        {
          prop: "created_at",
          name: "操作时间",
          type: 1
        },
        {
          prop: "remark",
          name: "备注",
          type: 1
        }
      ],
      tableTitle: [
        {
          prop: "ipt_no",
          name: "住院号",
          type: 1,
          width: "80"
        },
        {
          prop: "name",
          name: "姓名",
          type: 1,
          width: "80"
        },
        {
          prop: "id_card",
          name: "身份证",
          type: 1
        }
      ],
      tableData: [
        {
          ipt_no: "",
          id: "",
          name: "",
          id_card: ""
        }
      ],
      leftValue: "",
      //查询条件
      formInline: {
        rightKeyValue: "",
        rightRadio:["2"],
        range:'3',
        room:'',
        page:1,
        limit:10,
        times:''
      },
      getBuildlist:[],
        Radiooptions:[{
          value: '1',
          label: '待入院'
        }, {
          value: '2',
          label: '在院'
        }, {
          value: '3',
          label: '申请出院'
        }, {
          value: '4',
          label: '待出院'
        }, {
          value: '5',
          label: '已出院'
        }],
        Radiooptions2:[{
            value: '1',
          label: '个人'
        },
        {
           value: '2',
          label: '科室'
        },
        { value: '3',
          label: '全院'}
        ],
      total:0,
      fooddialogdeposit: false,
      foodinfo: {
        id: "",
        pid: ""
      },
      NurseLeveldialogdeposit: false,
      nlevelinfo: {
        id: "",
        pid: ""
      },
      ben_list: [],
      patientlist: [],
      //当前病人信息
      patientinfo: {
        nurse_levelneme: "",
        member: {
          name: "",
          gender: "",
          age: ""
        },
        wallet: {
          wallet_income: ""
        },
        doctor: { real_name: "" },
        nurse: { real_name: "" },
        room_name: ""
      },

      //判断当前选中
      index_t: 0,
      dialogFormVisible1: false,
      dialogdeposit: false,
       dialogdeposit2: false,
      //就病区{
      cancelHospitalinfo: {
        id: "",
        cancel_msg: ""
      },
      revoke: {
        id: "",
        cancel_msg: ""
      },
      //护士列表
      nuserlist: [],
      //医生列表
      duserlist: [],
      icuname: "",
      //押金
      orderinfo: {
        hospital_id: "",
        remark: "",
        des: "",
        payment: [
          {
            payment: 1,
            money: 0
          },
          {
            payment: 2,
            money: 0
          },
          {
            payment: 3,
            money: 0
          },
          {
            payment: 4,
            money: 0
          },
          {
            payment: 5,
            money: 0
          },
          {
            payment: 6,
            money: 0
          }
        ]
      },
      moneysum: 0,
      damoneysum: "",
      canceldialogdeposit: false,
      posiDetaillist:[],
      diet_list: [],
      huli: [],
      userdata: {},
      disease:[]
    };
  },
  watch: {
    index(to) {
      if (to == 0) {
        that.loading.close();
      } else {
        that.loading = that.$loading({
          lock: true,
          text: "",
          background: "rgba(0, 0, 0, 0.7)"
        });
      }
    }
  },
  mounted() {
    that = this;
    that.getHospitalMember();
    that.getNurseLevel()
    that.getmember_lv()
       getAllIcu({level:'2'}).then(res=>{
      this.getBuildlist=res.data
    })
    that.$refs.userinfn.readHospitalMemberDetail(patientinfo.id)

  },
  methods: {
    yujiaokuan(){
          this.shoujulogdeposit=true
    },
       //获取护理等级
    getNurseLevel() {
      getNurseLevel({}).then(res => {
        that.huli = res.data;
      });
    },
     //获取病人性质
     getmember_lv() {
      getdictIndex({ group_id: 4 })
        .then(res => {
          let data = res.data[0].items;
          data.forEach((item, key) => {

            let arr = {
              name: item.name,
              id: item.id
            };
            that.member_lv.push(arr);
          });
        })
        .catch(e => {});
    },
    //分页
    handleSizeChange(e){
       this.formInline.limit = e
       that.getHospitalMember()
     },
        handlePagination(e){

       this.formInline.page = e
       that.getHospitalMember()
       },
       radiochang(){
          that.getHospitalMember()
       },
    getHospitalMember() {
      let data_t = {
        ipt_no: "",
        m_keyword: that.formInline.rightKeyValue,
        times: that.formInline.times,
        room:that.formInline.room,
         status: that.formInline.rightRadio.toString(),
        page: that.formInline.page,
          range:that.formInline.range,
        limit: that.formInline.limit
      };
      getMemberDepositList(data_t)
        .then(res => {
          let data = res.data.list;
          that.total = res.data.count;
         that.patientlist=[]
          if (data.length != 0) {

            data.forEach((item, key) => {
              let arr = {
                ipt_no: item.ipt_no,
                id: item.id,
                name: item.member.name,
                id_card: item.member.id_card
              };
              that.tableData.push(arr);
            });
            that.patientlist = data;
            for (var i in that.patientlist) {
              that.patientlist[i].member.gender =
                that.patientlist[i].member.gender == 1
                  ? "男"
                  : that.patientlist[i].member.gender == 2
                  ? "女"
                  : "其他";
                         that.patientlist[i].nurse_levelneme = that.mapping(
                that.patientlist[i].nurse_level
              );
               that.patientlist[i].memberNature=that.mapxing(
                 that.patientlist[i].member.nature
               )
            // that.patientlist[i].diseaseName =  that.patientlist[i].disease.map(item=>{
            //   return item.disease_name
            // })
            //  that.patientlist[i].diseaseName =  that.patientlist[i].diseaseName.join("&")

            }

            that.patientinfo = data[0];
          }
        })
        .catch(e => {
          this.$message({
            message: e.message,
            type: "error"
          });
        });
    },

      //
    mapping(num) {
      //  console.log(that.huli,'000000000')
      var art = "";
      for (var i in that.huli) {
        if (that.huli[i].id == num) {
          // console.log(that.huli[i],'000000000')
          art = that.huli[i].name;
        }
        return art;
      }
    },
    //匹配斌人性质
     mapxing(num) {
      //  console.log(that.huli,'000000000')
      var art = "";
      for (var i in that.member_lv) {
        if (that.member_lv[i].id == num) {
          // console.log(that.huli[i],'000000000')
          art = that.member_lv[i].name;
        }
        return art;
      }
    },

    //切换病人
    Select(i) {
      // that.index_t = i;
      that.patientinfo = that.patientlist[i];

    },
    handleCommand(command) {
      console.log( command)
      let arr = command
    this.Select(arr[1])


         switch (arr[2]) {
           //押金
        case 'y':
         that.dialogdeposit = true;
        break;
        case 'tk':
          that.dialogdeposit2 = true;
        break;
         case 'mx':
            getDeposiDetail({hospital_id:arr[0]}).then(res=>{
          that.posiDetaillist=res.data.lists
          for (let i = 0; i < that.posiDetaillist.length; i++) {
             that.posiDetaillist[i].get_user_real_name=that.posiDetaillist[i].get_user.real_name

          }

      })
      that.dialogdeposit3=true
        break;
          case 'dy':
          that.yujiaokuan()
        break;

          }
    },
        handedeposit() {
      var data_tt = that.orderinfo;
      data_tt.hospital_id = that.patientinfo.id;
      createDepositOrder(data_tt)
        .then(res => {

          if (res.code==200) {
            this.$message({
                  message: "成功",
                  type: "success"
                });
                this.dialogdeposit2=true
          }
         that.getHospitalMember()
          // that.dialogdeposit = false;
        })
        .catch(e => {});
    },
    refundDeposit(){
      var data_tt = that.orderinfo;
      data_tt.hospital_id = that.patientinfo.id;
          refundDeposit(data_tt).then(res=>{
               this.$message({
                  message: "成功",
                  type: "success"
                });
                this.dialogdeposit2=true
                    that.getHospitalMember()
          // that.dialogdeposit2 = false;
          })
    },
    qingchu(){
            this.orderinfo={
        hospital_id: "",
        remark: "",
        des: "",
        payment: [
          {
            payment: 1,
            money: 0
          },
          {
            payment: 2,
            money: 0
          },
          {
            payment: 3,
            money: 0
          },
          {
            payment: 4,
            money: 0
          },
          {
            payment: 5,
            money: 0
          },
          {
            payment: 6,
            money: 0
          }
        ]
      }
      this.moneysum= 0
      this.damoneysum=""
    },
    rowclick(row){
      console.log(row)
            this.patientinfo=row
    },
    //押金总和
    moneysumfun() {
      var arr = that.orderinfo.payment;
      var num = 0;
      var num1 = that.NumberAdd(num, parseFloat(arr[0].money));
      var num2 = that.NumberAdd(num1, parseFloat(arr[1].money));
      var num3 = that.NumberAdd(num2, parseFloat(arr[2].money));
      var num4 = that.NumberAdd(num3, parseFloat(arr[3].money));
      var num5 = that.NumberAdd(num4, parseFloat(arr[4].money));
      that.moneysum = that.NumberAdd(num5, parseFloat(arr[5].money));
      that.damoneysum = that.AmountLtoU(that.moneysum);
    },
    AmountLtoU(num) {
      ///<summery>小写金额转化大写金额</summery>
      ///<param name=num type=number>金额</param>
      if (isNaN(num)) return "";
      var strPrefix = "";
      if (num < 0) strPrefix = "(负)";
      num = Math.abs(num);
      if (num >= 1000000000000) return "无效数值！";
      var strOutput = "";
      var strUnit = "仟佰拾亿仟佰拾万仟佰拾元角分";
      var strCapDgt = "零壹贰叁肆伍陆柒捌玖";
      num += "00";
      var intPos = num.indexOf(".");
      if (intPos >= 0) {
        num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
      }
      strUnit = strUnit.substr(strUnit.length - num.length);
      for (var i = 0; i < num.length; i++) {
        strOutput +=
          strCapDgt.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);
      }
      return (
        strPrefix +
        strOutput
          .replace(/零角零分$/, "整")
          .replace(/零[仟佰拾]/g, "零")
          .replace(/零{2,}/g, "零")
          .replace(/零([亿|万])/g, "$1")
          .replace(/零+元/, "元")
          .replace(/亿零{0,3}万/, "亿")
          .replace(/^元/, "零元")
      );
    },

  },
  components: {
    FromList,
    TopManu,
    ViewTitle,
    infocrad,
    costR
  }
};
</script>

<style lang="scss" scoped>
@import "./index.css";

.el-card__body {
  padding: 0px;
}


.hosptal-card {
  padding: 0px;
  width: 280px;
  min-height: 280px;
  box-sizing: border-box;
  font-family: "仿宋";
  .card-header {
    height: 80px;
    .card-header-img {
      width: 80px;
      height: 80px;
      border-radius: 60px;
    }
  }
  .card-title {
    font-weight: bold;
    font-size: 40px;
    text-align: center;
    background: #00ffff;
    height: 50px;
    line-height: 50px;
  }
  .card-span {
    font-size: 20px;
    color: #000000;
    font-weight: bold;
  }
  .card-span > div:nth-child(1) {
    padding-top: 10px;
  }
  .card-span > div:nth-child(2) {
    padding-top: 24px;
  }
  .card-radio {
    width: 30px;
    height: 30px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 30px;
    margin-top: 20px;
  }
  .card-label {
    display: flex;
    flex-wrap: wrap;

    // grid-template-columns: 1fr 1fr 1fr;
    // grid-gap:10px;
    div {
      margin-right: 10px;
      margin-bottom: 10px;
      padding: 0 10px;
      color: #fff;
      border-radius: 4px;
      background: #e9686b;
    }
  }

  .img_box {
    width: 46px;
    height: 46px;
  }
  .span_title {
    font-weight: bold;
  }
  .img_kong_box {
    margin: auto;
    width: 90%;
    margin-top: 90px;
  }
  .cardhover {
    width: 280px;
    min-height: 280px;
  }
  .cardhover:hover {
    background: #aeecd1c2;
  }
  .img_kong {
    width: 100%;
    height: auto;
    margin: auto;
  }
}
.separate {
    .dialog-text {
        font-size: 18px;
        margin-bottom: 20px;
        display: flex;
        justify-content: space-between;
    }
}
</style>
